package com.ml.springbootidus.cotroller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ml.springbootidus.mapper.UserInfosMapper;
import com.ml.springbootidus.pojo.UserInfo;
import com.ml.springbootidus.redis.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Readis 测试接口【注解】
 */
@RestController
public class UserInfoRController {
    @Autowired
    RedisTemplate redisTemplate;
    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @Autowired
    UserInfosMapper userInfosMapper;
    @Autowired
    private RedisService redisService;

    /**
     * 获取用户【Redis】
     *
     * @return 得到Redis里的用户，没有用户就存进去
     */
    @GetMapping("/getuserrs")
    @Cacheable(value = "thisredis", key = "#root.methodName")
    public List<UserInfo> getuserrs() {
        List<UserInfo> userList = userInfosMapper.selectList(new QueryWrapper<>());
        userList.forEach(System.out::println);
        if (userList != null) {
            return userList;
        } else {
            return null;
        }
    }






}
